package com.vnp.cooking.bean;

import java.util.ArrayList;

import org.json.JSONArray;
import org.json.JSONObject;

import android.os.Parcel;
import android.os.Parcelable;

public class ObjAttribute implements Parcelable {
	String alias;
	String name;
	int id;

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	String valueSort;
	String nameSort;

	public ObjAttribute() {

	}

	public ObjAttribute(Parcel p) {
		alias = p.readString();
		name = p.readString();
		id = p.readInt();
	}

	public ObjAttribute(String alias, String name) {
		this.alias = alias;
		this.name = name;
	}

	public String getAlias() {
		return alias;
	}

	public void setAlias(String alias) {
		this.alias = alias;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getValueSort() {
		return valueSort;
	}

	public void setValueSort(String valueSort) {
		this.valueSort = valueSort;
	}

	public String getNameSort() {
		return nameSort;
	}

	public void setNameSort(String nameSort) {
		this.nameSort = nameSort;
	}

	@Override
	public int describeContents() {
		return 0;
	}

	@Override
	public void writeToParcel(Parcel dest, int flags) {
		dest.writeString(alias);
		dest.writeString(name);
		dest.writeInt(id);
	}

	public static final Parcelable.Creator<ObjAttribute> CREATOR = new Parcelable.Creator<ObjAttribute>() {
		public ObjAttribute createFromParcel(Parcel p) {
			return new ObjAttribute(p);
		}

		public ObjAttribute[] newArray(int size) {
			return new ObjAttribute[size];
		}
	};

	public static ArrayList<ObjAttribute> jsToArrayList(String jsstr) {
		ArrayList<ObjAttribute> items = new ArrayList<ObjAttribute>();
		try {
			JSONArray jsa = new JSONArray(jsstr);
			for (int i = 0; i < jsa.length(); i++) {
				JSONObject jso = jsa.getJSONObject(i);
				String alias = jso.getString("alias");
				String name = jso.getString("name");
				int id = jso.getInt("id");
				ObjAttribute item = new ObjAttribute(alias, name);
				items.add(item);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return items;
	}

}
